//
//  Person+Scriptability.m
//  ScriptableDemo
//
//  Created by lg on 2020/5/27.
//  Copyright © 2020 lg. All rights reserved.
//

#import "Person+Scriptability.h"
#import "AppDelegate.h"
#import "NSObject+Scriptability.h"
#import "CustomScriptCommand.h"

@implementation Person (Scriptability)

- (NSScriptObjectSpecifier *)objectSpecifier {
    NSScriptClassDescription* appDesc = (NSScriptClassDescription*)[NSApp classDescription];
    return [[NSNameSpecifier alloc] initWithContainerClassDescription:appDesc containerSpecifier:nil key:@"personsArray" name:self.name];
//    return [[NSUniqueIDSpecifier alloc] initWithContainerClassDescription:appDesc containerSpecifier:nil key:@"personsArray" uniqueID:[NSNumber numberWithInteger:self.uid]];
}

- (void)scripterSaysPair:(CustomScriptCommand *)command {
    NSLog(@"%s", __func__);
    id receiver = [command evaluatedReceivers];
    id args = [command evaluatedArguments];
    NSLog(@"%@:%@", receiver, args);
    
    Person *p1 = [command evaluatedReceivers];
    Person *p2 = [[command evaluatedArguments] valueForKey:@"otherPerson"];
    
    if (self != p1 || self == p2) {
        [self returnError:errOSACantAssign string:@"不能操作"];
        return;
    }
}
@end
